$(function () {
    let $account = $("#account")
    let $password = $("#password")
    let $repassword = $("#repassword")
    let $nickname = $("#nickname")
    let $btn_submit = $("#btn_submit")
    $btn_submit.click(function () {
        let options = {
            url: "http://127.0.0.1:8888/users/register",
            type: "POST",
            data: {
                username: $account.val(),
                password: $password.val(),
                rpassword: $password.val(),
                nickname: $nickname.val(),
            },
            dataType: "json",
        }
        $.ajax(options)
        .done(function (data) {
                console.log(data);
                switch (data.code) {
                    case 0:
                        error_register(data.message)
                        break;
                    case 1:
                        syccess_register(data.message)
                }
            })
            function error_register(word){
                 $("#login").css({ display:"block",}).removeClass("alert-success").addClass("alert-danger").html(word)
                 setTimeout(function(){
                    $("#login").css({display:"none"})
                    
                 },2000)
                 
            }
            function syccess_register(word){
                $("#login").css({display:"block"}).removeClass("alert-danger").addClass("alert-success").html(word)
                setTimeout(function(){
                        $("#login").css({display:"none"})
                        location.href="../../dist/login.html"
                        
                     },2000)
            }
    })

})